package vj.stack;

import java.util.Iterator;
import java.util.Stack;

public class InvertStack {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Stack<String> stk = new Stack<String>();
		stk.push("A");
		stk.push("F");
		stk.push("K");
		stk.push("Z");
		invertStack(stk);
		Iterator<String> it = stk.iterator();
		System.out.println(stk.peek());
		while(it.hasNext()){
			System.out.println(it.next());
		}

	}
	
	public static <T> void invertStack(Stack<T> stk) {
		if(!stk.isEmpty()) {
			T t = stk.pop();
			if(!stk.isEmpty())
				invertStack(stk);
			stk.push(t);
		}
	}

}
